This sample demonstrates how to use the Calendar class in the Windows.Globalization namespace to manipulate and process dates based on a calendar system and the user's globalization preferences.
Note This sample was created using one of the universal app templates available in Visual Studio. It shows how its solution is structured so it can run on both Windows 8.1 and Windows Phone 8.1. For more info about how to build apps that target Windows and Windows Phone with Visual Studio, see Build apps that target Windows and Windows Phone 8.1 by using Visual Studio.
The Calendar API is in the Windows.Globalization namespace. It provides the caller with the details of either the user's default calendar or a caller-specified calendar system. The API gives access to specific statistical details as well as the ability to perform calendar-aware math operations. In JavaScript/HTML apps, the calendar can be converted to or from a standard JavaScript Date object.
This sample contains scenarios that demonstrate:
- How to create a calendar for the user's default preferences or for specific overrides, and how to display calendar details.
- How to determine statistics for the current calendar date and time, such as the number of days in this month and the number of months in this year.
- How to enumerate through a calendar and perform calendar math, such as determining the number of hours in a day that spans the transition from Daylight Saving Time.
- How to create a calendar using language names with supported Unicode extension tags, and how the extension tags are used by the calendar object.
- How to support time zones in calendars, by changing several time zones within a calendar and showing the effect of the time zone change in the date and time properties of the calendar.
To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.
To obtain an evaluation copy of Microsoft Visual Studio 2013 Update 2, go to Microsoft Visual Studio 2013.
Related topics
Operating system requirements
| Client | |
|---|---|
| Server | |
| Phone |
Build the sample
- Start Visual Studio 2013 Update 2 and select File > Open > Project/Solution.
- Go to the directory to which you unzipped the sample. Then go to the subdirectory named for the sample and double-click the Visual Studio 2013 Update 2 Solution (.sln) file.
- Follow the steps for the version of the sample you want:
-
To build the Windows version of the sample:
- Select CalendarSample.Windows in Solution Explorer.
- Press Ctrl+Shift+B, or use Build > Build Solution, or use Build > Build CalendarSample.Windows.
-
To build the Windows Phone version of the sample:
- Select CalendarSample.WindowsPhone in Solution Explorer.
- Press Ctrl+Shift+B or use Build > Build Solution, or use Build > Build CalendarSample.WindowsPhone.
-
Run the sample
The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it.
Deploying the sample
-
To deploy the built Windows version of the sample:
- Select CalendarSample.Windows in Solution Explorer.
- Use Build > Deploy Solution or Build > Deploy CalendarSample.Windows.
-
To deploy the built Windows Phone version of the sample:
- Select CalendarSample.WindowsPhone in Solution Explorer.
- Use Build > Deploy Solution or Build > Deploy CalendarSample.WindowsPhone.
Deploying and running the sample
-
To deploy and run the Windows version of the sample:
- Right-click CalendarSample.Windows in Solution Explorer and select Set as StartUp Project.
- To debug the sample and then run it, press F5 or use Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.
-
To deploy and run the Windows Phone version of the sample:
- Right-click CalendarSample.WindowsPhone in Solution Explorer and select Set as StartUp Project.
- To debug the sample and then run it, press F5 or use Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.